local skel = fk.CreateSkill {
  name = "emo__niangkou",
}

Fk:loadTranslationTable{
  ["emo__niangkou"] = "酿寇",
  [":emo__niangkou"] = "你可将任意张不同名的基本牌当伤害值为等量的【杀】使用。你放弃过使用基本牌的阶段结束时，你可使用一张【杀】或摸一张牌。",
  -- 放弃过使用基本牌的阶段：此阶段张燕有过“需使用一张基本牌”这个时机，但未于该时机使用牌。

  ["#emo__niangkou"] = "酿寇:将任意张不同名的基本牌当伤害值为等量的【杀】使用",
  ["#emo__niangkou-use"] = "酿寇:选择使用一张【杀】，不使用则摸一张牌",
  ["#emo__niangkou-ask"] = "酿寇:你可以选择是否摸牌或使用【杀】",
}

skel:addEffect("viewas", {
  prompt = "#emo__niangkou",
  anim_type = "offensive",
  mute_card = false,
  pattern = "slash",
  min_card_num = 1,
  card_filter = function (self, player, to_select, selected)
    local card = Fk:getCardById(to_select)
    return card.type == Card.TypeBasic and table.every(selected, function (id)
      return Fk:getCardById(id).trueName ~= card.trueName
    end)
  end,
  view_as = function (self, player, cards)
    if #cards == 0 then return nil end
    local c = Fk:cloneCard("slash")
    c.skillName = skel.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    use.additionalDamage = #use.card.subcards - 1
  end,
})

skel:addEffect(fk.EventPhaseEnd, {
  anim_type = "offensive",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and
    (player:getMark("emo__niangkou-phase") ~= 0 or (target == player and player.phase == Player.Play))
    -- 自己的出牌阶段稳定触发一次
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#emo__niangkou-ask" })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local use = room:askToUseCard(player, {
      pattern = "slash", skill_name = skel.name, prompt = "#emo__niangkou-use", extra_data = {bypass_times = true}
    })
    if use then
      use.extraUse = true
      room:useCard(use)
    elseif not player.dead then
      player:drawCards(1, skel.name)
    end
  end,
})

--- 询问使用后，判断需要使用基本牌，但是未使用的情况
skel:addEffect(fk.AfterAskForCardUse, {
  late_refresh = true, -- 在所有技能结算后再判断
  can_refresh = function (self, event, target, player, data)
    if player:hasSkill(skel.name, true) and target == player and player:getMark("emo__niangkou-phase") == 0 then
      return Exppattern:Parse(".|.|.|.|.|basic"):matchExp(data.pattern) -- 需要使用基本牌
      and type(data.result) ~= "table" -- 无结果，即未使用
    end
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "emo__niangkou-phase", 1)
  end,
})

return skel
